﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;

namespace MoneyWentWhere.WinFormsUI
{
    static class ExtensionMethods
    {
        public static void ReplaceColumnWithComboBox(this DataGridView view, String colName, 
            object dataSource)
        {
            DataGridViewColumn orig = view.Columns[colName];
            DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
            cb.HeaderText = orig.HeaderText;
            cb.DataPropertyName = orig.DataPropertyName;
            cb.FlatStyle = FlatStyle.Flat;

            cb.DataSource = dataSource;

            view.Columns.Insert(orig.Index, cb);
            view.Columns.RemoveAt(orig.Index);
        }

        public static T GetColumn<T>(this DataGridView view, String colName)
            where T : DataGridViewColumn
        {
            return (T)view.Columns[colName];
        }

        public static void AddItems<T>(this IList<T> list, params T[] items)
        {
            foreach (T item in items) { list.Add(item); }
        }
    }
}
